#!/usr/bin/env python
# -*- coding: utf-8 -*-
from string import Template
from tack.lib import json_app, content_headers, status_codes
from tack_ocie.api.util import build_row_dict


get_all_sql = """
SELECT * FROM ocie_appointment_type
ORDER BY appointment_type_id
"""


def get_all(environ, start_response):
    sql = Template(get_all_sql).substitute(locals())
    cursor = environ['connection'].cursor()
    cursor.execute(sql)
    rows = cursor.fetchall()
    output = []
    for row in rows:
        row_dict = build_row_dict(cursor.description, row)
        output.append(row_dict)
    return json_app(output)(environ, start_response)
